package com.ruoyi.car.controller.carmanage;

import java.util.List;

import com.car.pojo.TbCarSale;
import com.ruoyi.car.service.carmanage.ITbCarSaleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆销售信息Controller
 *
 * @author 韩昊昌
 * @date 2020-06-25
 */
@Controller
@RequestMapping("/sale/sale")
public class TbCarSaleController extends BaseController
{
    private String prefix = "/car/sale";

    @Autowired
    private ITbCarSaleService tbCarSaleService;

    @RequiresPermissions("sale:sale:view")
    @GetMapping()
    public String sale()
    {
        return prefix + "/sale";
    }

    /**
     * 查询车辆销售信息列表
     */
    @RequiresPermissions("sale:sale:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbCarSale tbCarSale)
    {
        startPage();
        List<TbCarSale> list = tbCarSaleService.selectTbCarSaleList(tbCarSale);
        return getDataTable(list);
    }





    /**
     * 查询入库和销售的信息
     */






    /**
     * 导出车辆销售信息列表
     */
    @RequiresPermissions("sale:sale:export")
    @Log(title = "车辆销售信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbCarSale tbCarSale)
    {
        List<TbCarSale> list = tbCarSaleService.selectTbCarSaleList(tbCarSale);
        ExcelUtil<TbCarSale> util = new ExcelUtil<TbCarSale>(TbCarSale.class);
        return util.exportExcel(list, "sale");
    }

    /**
     * 新增车辆销售信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆销售信息
     */
    @RequiresPermissions("sale:sale:add")
    @Log(title = "车辆销售信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbCarSale tbCarSale)
    {
        return toAjax(tbCarSaleService.insertTbCarSale(tbCarSale));
    }

    /**
     * 修改车辆销售信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbCarSale tbCarSale = tbCarSaleService.selectTbCarSaleById(id);
        mmap.put("tbCarSale", tbCarSale);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆销售信息
     */
    @RequiresPermissions("sale:sale:edit")
    @Log(title = "车辆销售信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbCarSale tbCarSale)
    {
        return toAjax(tbCarSaleService.updateTbCarSale(tbCarSale));
    }

    /**
     * 删除车辆销售信息
     */
    @RequiresPermissions("sale:sale:remove")
    @Log(title = "车辆销售信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbCarSaleService.deleteTbCarSaleByIds(ids));
    }
}
